package com.sql.parse;

import java.util.Collection;
import java.util.Map;

/**
 * @Author xiaoqiang
 * @Version SqlParseManager.java, v 0.1 2024年07月15日 上午11:44 xiaoqiang
 * @Description: TODO
 */
public class SqlParseManager {

    /**
     * 解析普通sql 占位符默认是 #{}
     *
     * example：
     * String sqlTemplate = "select * from user where name = #{name}";
     *         Map<String,Object> map = new HashMap<>();
     *         map.put("name","小强");
     * select * from user where = '小强'
     * @param sqlTemplate
     * @param params
     * @return
     */

    public static String parse(String sqlTemplate, Map<String,Object> params) {
        SqlParseProcess process = new SqlParseProcess();
        return process.parseText(sqlTemplate,params);
    }

    /**
     * example：
     * String sqlTemplate = "select * from user where name = @{name}";
     * Map<String,Object> params = new HashMap<>();
     * params.put("name","小强");
     * PlaceHolder holder = new PlaceHolder();
     * holder.setPrefix("@{");
     * holder.setSuffix("}");
     * String sql = parse(sqlTemplate,params,Lists.newArrayList(holder));//select * from user where = '小强'
     *
     *
     *
     * select * from user where = '小强'
     * @param sqlTemplate sql 模版
     * @param params 参数
     * @param placeHolders 指定占位符 可以是多个
     * @return
     */
    public static String parse(String sqlTemplate, Map<String, Object> params, Collection<PlaceHolder> placeHolders) {

        SqlParseProcess process = new SqlParseProcess();
        return process.parseText(sqlTemplate,params,placeHolders);
    }
}
